﻿@using Contrib.Taxonomies.Services

@{
    var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;
    var taxonomyService = WorkContext.Resolve<ITaxonomyService>();
}

@if (Model.Terms.Count > 0) {
<p class="taxonomy-field">
    <span class="name">
        @(new HtmlString( string.Join(", ", terms.Select(t => {
            var firstOrDefault = taxonomyService.GetParents(t).FirstOrDefault();
            return firstOrDefault != null ? Html.ItemDisplayLink(firstOrDefault.Name + " - " + t.Name, t.ContentItem ).ToString() : null; }).ToArray()) ))
    </span> 
</p>
}
